package com.syp.auth.export.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.syp.auth.export.common.GeneralUserVo;
import com.syp.auth.export.request.AppLogRequest;
import com.syp.auth.export.resource.AuthorizeResourceI;
import com.syp.auth.export.response.AppLogResponse;

public class AppLogTask implements Runnable {	
	private static final Logger log = LoggerFactory.getLogger(AppLogTask.class);

	private final AuthorizeResourceI proxy;
	private final AppLogRequest logRequest;

	public AppLogTask(AuthorizeResourceI proxy, GeneralUserVo guser, String clientIp, String uri) {
		this.proxy = proxy;
		this.logRequest = new AppLogRequest();

		this.logRequest.setUserId(guser.getId());
		this.logRequest.setUserCode(guser.getUserCode());
		this.logRequest.setUserName(guser.getUserName());
		this.logRequest.setAppCode(guser.getApp());
		this.logRequest.setClientIp(clientIp);
		this.logRequest.setOpresuri(uri);
	}

	@Override
	public void run() {
		try {
			AppLogResponse respone = proxy.log(logRequest);
			log.debug("记录操作日志结果：{}", respone.toString());
		} catch (Exception e) {
			log.error("记录操作日志异常", e);
		}
	}

}
